package fun._6742.model.dataobject;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import fun._6742.request.RegisterRequest;
import fun._6742.request.UpdateUserInfoRequest;
import lombok.*;
import fun._6742.enums.AuthorizationTypeEnums;
import fun._6742.request.AdminRegisterRequest;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author LiuQ
 * @since 2022-09-18
 */
@Data
@Builder
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
public class UserDO implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 昵称
     */
    private String name;

    /**
     * 密码
     */
    private String pwd;

    /**
     * 头像
     */
    private String headImg;

    /**
     * 用户签名
     */
    private String slogan;

    /**
     * 0表示女，1表示男
     */
    private Integer sex;

    /**
     * 积分
     */
    private Integer points;

    private Date createTime;

    /**
     * 邮箱
     */
    private String mail;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 盐，用于个人敏感信息处理
     */
    private String secret;

    /**
     * 用户类型
     */
    private Integer userType;

    public UserDO(AdminRegisterRequest adminRegisterRequest) {
        this.name = adminRegisterRequest.getName();
        this.pwd = adminRegisterRequest.getPwd();
        this.phone = adminRegisterRequest.getPhone();
        this.createTime = new Date();
        this.userType = AuthorizationTypeEnums.SHOPKEEPER.getCode();
    }

    public UserDO(RegisterRequest registerRequest) {
//        this.name = registerRequest.getName();
        this.pwd = registerRequest.getPwd();
//        this.mail = registerRequest.getMail();
        this.phone = registerRequest.getPhone();
        this.createTime = new Date();
        this.userType = AuthorizationTypeEnums.COSTUMER.getCode();
    }

    public UserDO(Long id, UpdateUserInfoRequest updateUserInfoRequest) {
        this.id = id;
        BeanUtil.copyProperties(updateUserInfoRequest, this);
    }
}
